import os
from conanbase import ConanBase

class AppConan(ConanBase):
    settings = None

    def build(self):
        pass

    def package_info(self):
        pass

    def package(self):
        pkg_folder  = self.deps_cpp_info
        vpd_vendor = os.path.join(pkg_folder["vpd"].rootpath, "include", "vendor")

        board_path = self._get_borad_path()
        profile = os.path.join(board_path, "profile.txt")

        with open(profile) as fp:
            for line in fp:
                line = line.replace("\n", "").strip()
                if not line:
                    continue
                
                sr_path = os.path.join(vpd_vendor, line)
                if not os.path.isfile(sr_path):
                    print(sr_path)
                    sr_path = os.path.join("./", line)
                    if not os.path.isfile(sr_path):
                        raise FileNotFoundError(f"{sr_path} not found!")

                sr_file = os.path.basename(sr_path)
                sr_src_dir = os.path.dirname(sr_path)
                _, ext = os.path.splitext(sr_file)
                sr_dst_dir = os.path.join("opt", "bmc", ext[1:])
                self.copy(sr_file, src=sr_src_dir, dst=sr_dst_dir)


    def _get_borad_path(self):
        board_path = os.path.join("./", str(self.options.board_name))
        if os.path.isdir(board_path):
            return board_path
        raise FileNotFoundError(f"{board_path} not found!")